package com.nondo.rdp.finance.domain.setting.advert;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.nondo.rdp.core.domain.attach.Attach;
import com.nondo.rdp.core.domain.base.BaseEntity;
import com.nondo.rdp.finance.config.DbConfig;

import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 广告
 */
@Entity
@Table(name = DbConfig.DEFAULT_TABLE_PREFIX + "advert")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Advert extends BaseEntity {
	private static final long serialVersionUID = -2931349876968540252L;
	private Long id; // 主键ID
	private Integer type; // 类型 0=用户引导,1=课程广告,2=首页引导
	private String value; // 值
	private String title; // 标题
	private Attach image; // 图片
	private String url; // 链接
	private String ext; // 扩展
	private int openMode; // 打开方式 0=网页，1=原生
	private int sort; // 排序
	private int isShow; // 显示 0|1
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@NotNull(message = "类型不能为空")
	@Column(columnDefinition = "int default 0", nullable = false)
	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@NotNull(message = "标题不能为空")
	@Length(min = 2, max = 12, message = "标题长度必须介于2到12之间")
	@Column(name = "title", length = 20)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@OneToOne(cascade = CascadeType.ALL)
	public Attach getImage() {
		return image;
	}

	public void setImage(Attach image) {
		this.image = image;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public int getOpenMode() {
		return openMode;
	}

	public void setOpenMode(int openMode) {
		this.openMode = openMode;
	}

	@Column(columnDefinition = "int default 0", nullable = false)
	public int getSort() {
		return sort;
	}

	public String getExt() {
		return ext;
	}

	public void setExt(String ext) {
		this.ext = ext;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}

	public int getIsShow() {
		return isShow;
	}

	@Column(columnDefinition = "int default 1", nullable = false)
	public void setIsShow(int isShow) {
		this.isShow = isShow;
	}

}
